import { Modal } from 'antd';
import { ProTable } from '@ant-design/pro-components';
import React from 'react'

interface CreateFormProps{
  modelVisible:boolean;
  isEdit:boolean;
  columns:Array<{}>;
  defaultData:{};
  onCancel: ()=> void;
  onSubmit:(value:any)=>void;
}

const CreateForm: React.FC<CreateFormProps> =({modelVisible,isEdit, defaultData, onCancel, columns, onSubmit}) => {
  return (
    <Modal
      destroyOnClose
      title={isEdit?'编辑':'新建'}
      width={420}
      open={modelVisible}
      onCancel={()=>onCancel()}
      footer={null}
    >
      <ProTable<API.UserInfo, API.UserInfo>
        onSubmit={async (value) => {
          onSubmit(value)
        }}
        rowKey="id"
        type="form"
        columns={columns}
        form={{initialValues:defaultData}}
      />
    </Modal>
  )
}

export default CreateForm